package com.example.springbootdatajpa.repositories;

import com.example.springbootdatajpa.entities.Department;
import com.example.springbootdatajpa.entities.DeptEmpDto;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface DepartmentRepository extends JpaRepository<Department,Integer> {
    @Query("SELECT new com.example.springbootdatajpa.entities.DeptEmpDto(d.name,e.name,e.email,e.address) FROM Department d LEFT JOIN d.employees e")
    List<DeptEmpDto> fetchEmpDeptDataLeftJoin();

    @Query("SELECT new com.example.springbootdatajpa.entities.DeptEmpDto(d.name,e.name,e.email,e.address) FROM Department d RIGHT OUTER JOIN d.employees e")
    List<DeptEmpDto> fetchEmpDeptDataRightJoin();

    @Query("SELECT new com.example.springbootdatajpa.entities.DeptEmpDto(d.name,e.name,e.email,e.address) FROM Department d INNER JOIN d.employees e")
    List<DeptEmpDto> fetchEmpDeptDataInnerJoin();

    @Query("SELECT new com.example.springbootdatajpa.entities.DeptEmpDto(d.name,e.name,e.email,e.address) FROM Department d,Employee e")
    List<DeptEmpDto> fetchEmpDeptDataCrossJoin();
}
